#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
import urllib
import socket

socket.setdefaulttimeout(10)

videos = open('/home/chaojiansong/videobook/notinsvn/video_score_list.uniq', 'r')
uploaders = open('/home/chaojiansong/videobook/notinsvn/uploader_list', 'w')

def get_info(reg, data):
    m = re.search(reg, data)
    if m:
        return m.group(1)
    return 'zenmemeixiaxialaine'

def get_uploader(id):
    url = "http://api.youku.com/api_ptvideoinfo/pid/XMTI5Mg==/id/" + id + "/rt/xml"
    data = urllib.urlopen(url).read()
    uploader = get_info('<user><!\\[CDATA\\[(.*)\\]\\]></user>', data)
    if uploader != 'zenmemeixiaxialaine':
    	uploaders.write(uploader + '\n')

line_no = 0
for line in videos:
    if line_no % 6 == 0:
        get_uploader(line.rstrip())
    line_no = line_no + 1

uploaders.close()
videos.close()
